from reportlab.pdfgen import canvas
from PIL import Image
import os, sys

def chars(x):
    return x

def main(a1):

    v1 = sorted(os.listdir(a1), key = chars)
    v2 = list(map(os.path.join, [a1]*len(v1), v1))

    v3_w, v4_h=Image.open(v2[0]).size

    c=canvas.Canvas(os.path.basename(a1)+'.pdf',pagesize=(v3_w, v4_h))

    for i1 in v2:
        try:

            c.drawImage(i1, 0, 0, v3_w, v4_h)
            c.showPage()
            
        except: pass
    c.save()

if __name__ == "__main__":
    if not len(sys.argv) <2:
        main(sys.argv[1])
    else:
        print("\tTo merge pictures into a pdf,")
        print("\tUse the tool via:")
        print("\tpython [*this] [*dir*]")
        